package com.caine.androidtask.ls21.client;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.caine.androidtask.R;
import com.caine.androidtask.ls14.Utils;
import com.caine.androidtask.ls20.FileBrowser;

public class ClientActivity extends Activity implements OnClickListener{
   
	private EditText allMsg ;
	private EditText mMsg ;
	private Button btn_send;
	private EditText nikeName;
	LinearLayout layout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.caine_ls21_client_activity);
		init();
	}
	
	void init(){
		dialog();
		allMsg = (EditText) findViewById(R.id.ls21_allmsg);
		mMsg = (EditText) findViewById(R.id.ls21_msg);
		btn_send = (Button) findViewById(R.id.ls21_btn_sendmsg);
		nikeName = new EditText(this);
		layout = new LinearLayout(this);
		layout.setLayoutParams(new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		layout.addView(nikeName);
		/**
		 *  layout
		 * */
		
		
		btn_send.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.ls21_btn_sendmsg){
			
			allMsg.setText(allMsg.getText()+"\n\t "+Utils.getLocaTime()+"\t\n" +mMsg.getText());
			mMsg.setText("");
			allMsg.setMovementMethod(ScrollingMovementMethod.getInstance());
			allMsg.setSelection(allMsg.getText().length(), allMsg.getText().length());
		}
	}
	
	
	private void dialog(){
		/**new AlertDialog.Builder(this)
		.setMessage("Are you sure exit?")
		 .setCancelable(false)
		 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				ClientActivity.this.finish();
				android.os.Process.killProcess(android.os.Process.myPid());
				System.exit(0);
			}
		})
		.setNegativeButton("No", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				dialog.cancel();
			}
		})
		.setView(nikeName)
		.create()
		.show();*/
		new AlertDialog.Builder(this).setView(layout).create().show();
	}
}
